#ifndef RENDERENGINE_H
#define RENDERENGINE_H

#import <GLKit/GLKit.h>

#include "RenderTarget.h"
#include "Model.h"
#include "Shader.h"

class RenderEngine
{
public:

	static void static_init()
	{
		render_target.init();
	}
	
	static void draw_texture(GLuint texture)
	{
        check_gl_error();
        
		glViewport(0, 0, RenderContex::window_width, RenderContex::window_height);
		glDisable(GL_CULL_FACE);
		glDisable(GL_DEPTH_TEST);
        RenderTarget::check_fbo_status();
		glClear(GL_DEPTH_BUFFER_BIT);
		auto& shader = ShaderManager::draw_texture;
		shader.use();
		shader.bind_texture("tex", texture, 0);
		ModelManager::screen_aligned_quad.render();
		glEnable(GL_CULL_FACE);
		glEnable(GL_DEPTH_TEST);
        
        check_gl_error();
	}
	
	static void set_render_target(const RenderTexture * color_texture, const DepthStencil * depth_stencil )
	{
		if (color_texture == nullptr && depth_stencil == nullptr)
		{
			render_target.unbind();
			return;
		}
		render_target.bind_and_set_render_texture(color_texture);
		render_target.bind_and_set_depth_stencil(depth_stencil);
	}

	static void set_render_target(int color_texture_size, RenderTexture ** color_textures, const DepthStencil * depth_stencil)
	{
		render_target.bind_and_set_render_texture(color_texture_size, color_textures);
		render_target.bind_and_set_depth_stencil(depth_stencil);
	}

    static void bind_default_renderbuffer()
    {
        [_view bindDrawable];
    }
    
	static RenderTarget render_target;
    static GLKView* _view;

private:
    RenderEngine();
    
};

#endif
